<template>
    <div class="detail-info">
      <div class="form-item">
        <h4>基本信息</h4>
        <el-form :model="ruleForm" :rules="rules" label-width="120px" ref="ruleForm" class="demo-ruleForm">
          <el-form-item label="分公司" required>
            <el-input v-model="branchName" style="width: 220px" disabled></el-input>
          </el-form-item>
          <el-form-item label="所属部门" required>
            <el-input v-model="orgName" style="width: 220px" disabled></el-input>
          </el-form-item>
          <!--<el-form-item label="所属仓库" required>-->
            <!--<el-select v-model="ruleForm.limit_store_id" filterable>-->
              <!--<el-option-->
                <!--v-for="item in storeList"-->
                <!--:label="item.name"-->
                <!--:value="item.id">-->
              <!--</el-option>-->
            <!--</el-select>-->
          <!--</el-form-item>-->
          <el-form-item label="客资类型" required @change="typeChange(val)">
            <el-select v-model="ruleForm.limit_user_type" disabled filterable>
              <el-option
                v-for="item in ruleForm.clientList"
                :label="item.name"
                :value="item.id">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="客户标签">
            <el-select v-model="ruleForm.limit_usertypetag_id" multiple filterable>
              <el-option
                v-for="item in labelList"
                :label="item.labelName"
                :value="item.labelCode"
                :disabled="item.disabled">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="活动名称" prop="name" required>
            <el-input v-model="ruleForm.name" style="width: 200px"></el-input>
          </el-form-item>
          <el-form-item label="主广告语" prop="ad_words">
            <el-input v-model="ruleForm.ad_words" style="width: 220px"></el-input>
          </el-form-item>
          <el-form-item label="副广告语" prop="sub_ad_words">
            <el-input v-model="ruleForm.sub_ad_words" style="width: 220px"></el-input>
          </el-form-item>
          <el-form-item label="广告图片">
            <el-upload
              class="avatar-uploader"
              :action="imgAddress"
              name="imageFile"
              :show-file-list="false"
              :on-success="success">
              <img v-if="this.ruleForm.ad_pic" :src="this.imgHost + '/' + this.ruleForm.ad_pic" class="avatar">
              <i v-else class="el-icon-plus avatar-uploader-icon"></i>
            </el-upload>
          </el-form-item>
          <el-form-item label="副标题" prop="title">
            <el-input v-model="ruleForm.title" style="width: 200px"></el-input>
          </el-form-item>
          <el-form-item label="活动起止时间" class="is-required">
            <el-date-picker
              :editable="false"
              v-model="ruleForm.time"
              type="datetimerange"
              value-format="yyyy-MM-dd HH:mm:ss"
              :picker-options="pickerOptions"
              @change="timeChange"
              placeholder="选择时间范围"
              :default-time="['00:00:00', '23:59:59']">
            </el-date-picker>
          </el-form-item>
          <el-form-item label="活动类型：" class="is-required">
            <el-radio-group v-model="ruleForm.limit_type">
              <el-radio label="2">每满元</el-radio>
              <el-radio label="1">阶梯</el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item v-show="ruleForm.limit_type === '2'" label="每满元：">
            满 <el-input v-model="ruleForm.limit_full_reduction[0].condition" style="width: 100px"></el-input> 元，
            减 <el-input v-model="ruleForm.limit_full_reduction[0].reduction" @change="" style="width: 100px"></el-input> 元,
            <span v-show="ruleForm.limit_full_reduction[0].condition && ruleForm.limit_full_reduction[0].reduction">(相当于 {{(((ruleForm.limit_full_reduction[0].condition - ruleForm.limit_full_reduction[0].reduction) / ruleForm.limit_full_reduction[0].condition) * 10).toFixed(1)}} 折)</span>
          </el-form-item>
          <span v-show="ruleForm.limit_type === '1'" class="stair">阶梯：</span>
          <el-form-item v-show="ruleForm.limit_type === '1'" v-for="(item, index) in ruleForm.stair">
            满 <el-input style="width: 100px"  v-model="item.condition "></el-input> 元，
            减 <el-input style="width: 100px"  v-model="item.reduction"></el-input> 元
            <span v-show="item.condition && item.reduction">(相当于 {{(((item.condition - item.reduction) / item.condition) * 10).toFixed(1)}} 折)</span>
            <el-button v-show="index !== 0 " @click.prevent="remove(index)">删除</el-button>
          </el-form-item>
          <el-form-item v-show="ruleForm.limit_type === '1'">
            <el-button @click="add_stair">新增阶梯</el-button>
          </el-form-item>
          <!--<el-form-item label="参与频次" prop="num" v-show="ruleForm.limit_type === '1'">-->
            <!--<el-input @blur="" v-model="ruleForm.num" style="width: 150px"></el-input> 次-->
          <!--</el-form-item>-->
          <!--<el-form-item label="含多比费用：" class="is-required">-->
            <!--<el-radio-group v-model="contain" @change="containChange">-->
              <!--<el-radio label="1">是</el-radio>-->
              <!--<el-radio label="2">否</el-radio>-->
            <!--</el-radio-group>-->
          <!--</el-form-item>-->
          <!--<el-form-item label="所属费用：" v-show="contain === '2'" class="is-required">-->
            <!--<el-select v-model="ruleForm.sales_cost" @change="fyChange2" filterable>-->
              <!--<el-option-->
                <!--v-for="(item, index) in feiyongList"-->
                <!--:label="item.promotionName"-->
                <!--:value="item.id"-->
                <!--:key="index">-->
              <!--</el-option>-->
            <!--</el-select>-->
          <!--</el-form-item>-->
          <!--<el-form-item label="供应商占比：" prop="sales_ratio" v-if="contain === '2' && type === true">-->
            <!--<el-input v-model="ruleForm.sales_ratio" style="width: 88px"></el-input>%-->
          <!--</el-form-item>-->
          <el-form-item label="商品类型">
            <el-select v-model="ruleForm.limit_product_type" placeholder="商品类型" style="width:220px" @change="productTypeChange">
              <el-option label="常规" value="10"></el-option>
              <el-option label="冷链" value="40"></el-option>
              <el-option label="鲜食" value="42"></el-option>
            </el-select>
          </el-form-item>
        </el-form>
      </div>
      <div class="form-item">
        <h4>商品信息</h4>
        <el-col :span="2">
          <el-button type="primary" @click="simpleCheck">添加商品</el-button>
        </el-col>
        <el-col :span="2">
          <el-button type="primary" @click="lotSet">批量设置</el-button>
          <!--<el-button :disabled="contain === '2'" type="primary" @click="lotSet">批量设置</el-button>-->
        </el-col>
        <el-col :span="6" class="daoru">
          <el-upload class="upload-demo"
            action="123"
            :before-upload="beforeUpload"
            :file-list="fileList"
            accept=".xlsx,.xls">
          <el-button :disabled="primaryDisabled" type="primary">导入表格</el-button>
            <div slot="tip" class="el-upload__tip">只能上传xlsx/xls文件，且只能上传一个文件</div>
          </el-upload>
        </el-col>
        <el-col :span="2">
          <el-button type="primary" size="small" style="">
            <a style="text-decoration:none; color:#fff" href="/static/template/商品活动模板.xlsx">下载模板</a>
          </el-button>
        </el-col>
        <el-table
          :data="tableData"
          :row-class-name="tableRowClassName"
          max-height="800"
          border
          style="width: 100%; margin-top: 10px">
          <el-table-column
            prop="productid"
            label="商品ID"
            align="center"
            width="80">
          </el-table-column>
          <el-table-column
            prop="name"
            show-overflow-tooltip
            label="商品名称"
            align="center"
            width="">
          </el-table-column>
          <el-table-column
            prop="saleunit"
            label="单位"
            align="center"
            width="">
            <template scope="scope">
              <span v-if="scope.row.saleunitFlag === true" :class="{ red: isRed, green: isGreen }">{{scope.row.saleunit}}</span>
              <span v-else>{{scope.row.saleunit}}</span>
            </template>
          </el-table-column>
          <el-table-column
            prop="salenorm"
            label="规格"
            align="center"
            width="">
            <template scope="scope">
              <span v-if="scope.row.salenormFlag === true" :class="{ red: isRed, green: isGreen }">{{scope.row.salenorm}}</span>
              <span v-else>{{scope.row.salenorm}}</span>
            </template>
          </el-table-column>
          <el-table-column
            prop="saleprice"
            label="系统售价"
            align="center"
            width="80">
            <template scope="scope">
              <span v-if="scope.row.salepriceFlag"  :class="{ red: isRed, green: isGreen }">{{scope.row.saleprice}}</span>
              <span v-else>{{scope.row.saleprice}}</span>
            </template>
          </el-table-column>
          <el-table-column
            prop="cgprice"
            label="上次入库成本价"
            align="center"
            width="120">
          </el-table-column>
          <el-table-column
            label="促销费用"
            align="center"
            min-width="120">
            <template scope="scope">
              <el-select v-model="scope.row.promotionfeetype" @change="val => { return fyChange(val, scope.row, scope.$index)}" filterable>
                <el-option
                v-for="(item, index) in feiyongList"
                :label="item.promotionName"
                :value="item.id"
                :key="index">
                </el-option>
              </el-select>
            </template>
          </el-table-column>
          <el-table-column
            label="供货商承担金额"
            align="center"
            width="120">
            <template scope="scope">
              <el-input @blur="moneyTest(scope.row, scope.$index)" v-show="scope.row.isSupplier" v-model="scope.row.providerholdprice"></el-input>
            </template>
          </el-table-column>
          <el-table-column
            label="操作"
            align="center"
            width="230">
            <template scope="scope">
              <el-button v-show="scope.$index !== 0" @click="top(scope.$index, scope.row)" size="small">置顶</el-button>
              <el-button v-show="scope.$index !== 0" @click="moveT(scope.$index, scope.row)" size="small">上移</el-button>
              <el-button v-show="scope.$index !== (tableData.length - 1)" @click="moveB(scope.$index, scope.row)" size="small">下移</el-button>
              <el-button @click="omit(scope.$index, scope.row)" size="small">删除</el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <div v-if="changeGoodFlag" class="detail-info" style="margin-top: 50px">
        <div class="form-item">
          <h4>异常商品信息</h4>
          <el-button type="primary" @click="changeGoodsClick">一键修改</el-button>
          <el-table :data="changeGoodsList" border style="margin-top:20px">
            <el-table-column prop="stateName" label="状态" align="center"></el-table-column>
              <!--<template scope="scope">-->
                <!--<span v-if="scope.row.canNotSale === true && scope.row.priceChange === true">下架,调价</span>-->
                <!--<span v-if="scope.row.canNotSale === true && scope.row.priceChangeIng === true">下架,调价中</span>-->
                <!--<span v-if="scope.row.canNotSale === true">下架</span>-->
                <!--<span v-if="scope.row.priceChange === true">调价</span>-->
                <!--<span v-if="scope.row.priceChangeIng === true">调价中</span>-->
                <!--<span v-else>调价</span>-->
              <!--</template>-->
            <!--</el-table-column>-->
            <el-table-column prop="productid" label="商品ID" align="center"></el-table-column>
            <el-table-column prop="name" label="商品名称" align="center"></el-table-column>
            <el-table-column prop="saleunit" label="销售单位" align="center"></el-table-column>
            <el-table-column prop="salenorm" label="销售规格" align="center"></el-table-column>
            <el-table-column prop="saleprice" label="系统售价" align="center"></el-table-column>
          </el-table>
        </div>
      </div>
      <div class="form-item">
        <el-form label-width="180px">
          <h4>备注</h4>
          <el-input  type="textarea"  placeholder="请输入活动说明" v-model="ruleForm.remark" style="width: 500px"></el-input>
        </el-form>
      </div>
      <div style="margin-left: 40%">
        <el-button type="primary" @click="submit($event, 'ruleForm')">提交</el-button>
        <el-button type="warning" @click="submit($event, 'ruleForm')">暂存</el-button>
        <el-button type="danger" @click="cancel">取 消</el-button>
      </div>
      <!--选择单品弹窗-->
      <el-dialog class="dialog" title="选择商品" :visible.sync="dialogSimple">
        <el-form style="margin-top: 20px; overflow: hidden" :inline="true" :model="formSimple" class="demo-form-inline">
          <el-form-item label="商品分类">
            <el-select v-model="formSimple.type1" style="width: 150px" filterable clearable @change="checkType2(formSimple.type1)">
              <el-option
                v-for="item in productList1"
                :label="item.cateName"
                :value="item.id">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-select v-model="formSimple.type2" style="width: 150px" filterable clearable @change="checkType3(formSimple.type2)">
              <el-option
                v-for="item in productList2"
                :label="item.cateName"
                :value="item.id">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-select v-model="formSimple.type3" style="width: 150px" filterable clearable>
              <el-option
                v-for="item in productList3"
                :label="item.cateName"
                :value="item.id">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="品牌">
            <el-select v-model="formSimple.brand" style="width: 150px" filterable clearable>
              <el-option
                v-for="item in brandList"
                :label="item.brandName"
                :value="item.brandId">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="商品ID">
            <el-input style="width: 100px" v-model="formSimple.ID"></el-input>
          </el-form-item>
          <el-form-item label="商品名称">
            <el-input style="width: 120px" v-model="formSimple.name"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="simpleList">搜索</el-button>
          </el-form-item>
        </el-form>
        <div>
          <el-button @click="lotAdd">批量添加</el-button>
        </div>
        <el-table
          :data="tableData2"
          v-loading="isLoading"
          height="400"
          ref="multipleTable"
          border
          style="width: 100%"
          @select-all="handleSelectionChange"
          @selection-change="handleChange">
          <el-table-column
            type="selection"
            :selectable="isCheck"
            width="55">
          </el-table-column>
          <el-table-column
            prop="hmpId"
            label="商品ID"
            align="center"
            width="100">
          </el-table-column>
          <el-table-column
            show-overflow-tooltip
            prop="hmpName"
            label="商品名称"
            align="center"
            width="200">
          </el-table-column>
          <el-table-column
            show-overflow-tooltip
            prop="saleunit"
            label="单位"
            align="center"
            width="100">
          </el-table-column>
          <el-table-column
            show-overflow-tooltip
            prop="salenorm"
            label="规格"
            align="center"
            width="100">
          </el-table-column>
          <el-table-column
            show-overflow-tooltip
            prop="price"
            label="系统售价"
            align="center"
            width="100">
          </el-table-column>
          <el-table-column
            show-overflow-tooltip
            prop="proBuyPrice"
            label="上次入库成本价"
            align="center"
            width="150">
          </el-table-column>
          <el-table-column
            label="操作"
            align="center"
            width="100">
            <template scope="scope">
              <el-button v-show="scope.row.name2 === 'add' && scope.row.isActivity === ''" @click="add(scope.$index, scope.row, $event)" size="small">添加</el-button>
              <el-button v-show="scope.row.name2 === 'cancel' && scope.row.isActivity === ''" @click="celadd(scope.$index, scope.row, $event)" size="small">撤销</el-button>
            </template>
          </el-table-column>
          <el-table-column
            prop="isActivity"
            label="当前活动"
            align="center"
            width="100">
          </el-table-column>
        </el-table>
        <el-pagination
          @current-change="handleCurrentChange"
          :page-size="Number(pageSize)"
          layout="total, prev, pager, next"
          :total="Number(total)"
          style="padding-top:10px;text-align: right;">
        </el-pagination>
      </el-dialog>
      <!--批量设置-->
      <el-dialog title="批量设置" size="tiny" top="30%" :visible.sync="dialogLotSet">
        <el-form :model="LotForm" :inline="true" label-width="120px" class="demo-form-inline" label-position="left" style="margin: 30px">
          <el-form-item label="所属费用">
            <el-select v-model="LotForm.feiyong" style="width: 196px" filterable @change="lotChange">
              <el-option
                v-for="item in feiyongList"
                :label="item.promotionName"
                :value="item.id">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="供应商承担金额" v-show="LotForm.show">
            <el-input v-model="LotForm.sum"></el-input>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="primary" @click="makeLot(LotForm.sum)">确 定</el-button>
        </div>
      </el-dialog>
      </div>
    </div>
</template>
<script>
  import { mapState } from 'vuex'
  import { apiHost, apiURL } from '../../../../../config/settings.js'
  import mixins from '../../../../../components/mixins.vue'
  import Vue from 'vue'
  import { getInfo, activity } from '../../../../../config/proxy.js'
  import axios from 'axios'
  export default {
    mixins: [mixins],
    data () {
      var checkName = (rule, value, callback) => {
        if (!value) {
          return callback(new Error('活动名称不能为空'))
        } else {
          callback()
        }
      }
      var checkTitle = (rule, value, callback) => {
        if (value.length > 20) {
          return callback(new Error('不能超过20个字'))
        } else {
          callback()
        }
      }
      var checkNum = (rule, value, callback) => {
        if (value && value <= 0) {
          callback(new Error('参与频次必须大于0'))
        } else {
          callback()
        }
      }
      var mainTest = (rule, value, callback) => { // 主广告语验证
        const reg = new RegExp('^[\u2E80-\u9FFF]+$', 'g')
        if (value && !reg.test(value)) {
          return callback(new Error('主广告语只能包含文字'))
        } else {
          callback()
        }
      }
      var salesRatio = (rule, val, callback) => { // 供应商占比验证
        var index2 = val.indexOf('.')
        var length2 = 0
        if (index2 !== -1) {
          const newIndex2 = val.substring(index2 + 1, val.length)
          length2 = newIndex2.length
        }
        if (isNaN(val) || (val < 0) || (length2 > 2)) {
          this.$message({
            showClose: true,
            message: '供货商承担占比大于0, 且最多为两位小数',
            type: 'error'
          })
          this.ruleForm.sales_ratio = ''
        } else {
          callback()
        }
      }
      var viceTest = (rule, value, callback) => { // 副广告语验证
        // const reg = new RegExp('^[\u4e00-\u9fa50-9]+$')
        const reg = /^(([\u2E80-\u9FFF]+)|([\u4e00-\u9fa50-9]+\.[\u4e00-\u9fa50-9]*[\u4e00-\u9fa51-9][\u4e00-\u9fa50-9]*)|([\u4e00-\u9fa50-9]*[\u4e00-\u9fa51-9][\u4e00-\u9fa50-9]*\.[\u4e00-\u9fa50-9]+)|([\u4e00-\u9fa50-9]*[\u4e00-\u9fa51-9][\u4e00-\u9fa50-9]*))$/
        if (value === '') {
          callback()
        } else {
          if (value[0] === '|') {
            return callback(new Error('副标题不能以”|“开头'))
          } else {
            var v = value.split('|')
            console.log(v)
            if (v.length > 2) {
              return callback(new Error('副广告语不能超过2行'))
            } else {
              for (let index = 0; index < v.length; index++) {
                const element = v[index]
                if (!reg.test(element)) {
                  console.log('错误')
                  return callback(new Error('副广告语只能包含文字和数字'))
                } else {
                  if (element.length > 8) {
                    return callback(new Error('长度不能超过8个字符'))
                  } else if (element.length === 0) {
                    return callback(new Error('长度不能少于1个字符'))
                  } else {
                    console.log('正确')
                    if (index === v.length - 1) {
                      callback()
                    }
                  }
                }
              }
            }
          }
        }
      }
      return {
        contain: '1', // 是否含有多比费用
        type: false,     // 费用类型
        arr: [],
        labelList: [],
        meimanDis: '',
        // 调价商品表格
        tableIndex: [], // 调价商品index数组
        changeGoodFlag: false,
        changeGoodsList: [],
        isRed: true,
        isGreen: false,
        rules: {
          ad_words: [ // 主广告语
            { min: 0, max: 6, message: '长度不能超过6个字符', trigger: 'blur' },
            { validator: mainTest, trigger: 'blur' }
          ],
          sub_ad_words: [ // 副广告语
            { validator: viceTest, trigger: 'blur' }
          ],
          title: [
            { validator: checkTitle, trigger: 'blur' }
          ],
          name: [
            { validator: checkName, trigger: 'blur' }
          ],
          num: [
            { validator: checkNum, trigger: 'blur' }
          ],
          sales_ratio: [
            { required: true, message: '请输入供应商承担占比', trigger: 'blur' },
//            { type: 'number', message: '请输入数字值', trigger: 'blur' },
            { validator: salesRatio, trigger: 'blur' }
          ]
        },
        pickerOptions: {
          disabledDate (time) {
            return time.getTime() < Date.now() - 8.64e7
          }
        },
//      基本信息
        data: '',
        datas: '',
        ruleForm: {
          limit_product_type: '10', // 商品类型
          sales_ratio: '',  // 供应商承担占比
          sales_cost: '',   // 费用
          ad_words: '',
          sub_ad_words: '',
          ad_pic: '',
          limit_usertypetag_id: '',
          clientList: [{
            id: 1,
            name: '普通超市'
          }],
          limit_store_id: '',
          limit_user_type: 1,
          name: '',
          title: '',
          time: [],
          start_time: '',
          end_time: '',
          limit_type: '2',
          limit_full_reduction: [
            {
              condition: '',
              reduction: ''
            }
          ],
          stair: [
            {
              condition: '',
              reduction: ''
            }
          ],
          num: '',
          remark: ''
        },
//      选择单品弹窗
        dialogSimple: false,
        brandList: [],
        productList1: [],
        productList2: [],
        productList3: [],
        formSimple: {
          type1: '',
          type2: '',
          type3: '',
          brand: '',
          ID: '',
          name: ''
        },
//      选择单品表格
        isLoading: false,
        tableData2: [],
        total: '',
        page: 1,
        pageSize: 10,
        all: [],
//      导入表格
        fileList: [],
        fileUrl: '',
        primaryDisabled: false,
//      商品信息
        tableData: [],
//      费用列表
        feiyongList: [],
//      批量设置弹窗
        dialogLotSet: false,
        LotForm: {
          feiyong: '',
          sum: '',
          show: true
        },
//      详情信息
        detailData: {},
        r: []
      }
    },
    methods: {
      productTypeChange (val) {
        this.tableData = []
      },
      testOver (arr) {
        arr.forEach((item, index) => {
          this.r.indexOf(item.promotionfeetype) ? item.promotionfeetype = '' : item.promotionfeetype = item.promotionfeetype
        })
      },
      containChange (val) {
        this.tableData.forEach((item, index) => {
          item.promotionfeetype = ''
        })
        this.ruleForm.sales_ratio = ''
        this.ruleForm.sales_cost = ''
      },
      fyChange2 (val) {
        this.feiyongList.forEach((item, index) => {
          if (item.id === val) {
            if (item.promotionType === 1) {
              this.type = false
            } else {
              this.type = true
            }
          }
        })
      },  // 不含多比费用时促销费用变化
      success (res) {
        this.ruleForm.ad_pic = res.content.imageUrl
      }, // 上传图片成功
      typeChange (val) {
        console.log(val)
      },
      moneyTest (row, index) {
        const val = row.providerholdprice
        var str = val.indexOf('.')
        var numlength = 0
        if (str !== -1) {
          const index = val.substring(str + 1, val.length)
          numlength = index.length
        }
        if (isNaN(val) || (val < 0) || (numlength > 2)) {
          this.$message({
            showClose: true,
            message: '供货商承担金额大于0, 最多为两位小数',
            type: 'error'
          })
          row.providerholdprice = ''
        }
      }, // 供货商承担金额验证----大于等于0, 两位小数
      fyChange (val, row, index2) {
        this.feiyongList.forEach((item, index) => {
          if (item.id === val) {
            console.log(item.promotionType)
            if (item.promotionType === 1) {
              row.isSupplier = false
              row.providerholdprice = ''
              Vue.set(this.tableData, index2, this.tableData[index2])
            } else {
              this.type = true
              row.isSupplier = true
              Vue.set(this.tableData, index2, this.tableData[index2])
            }
          }
        })
      },  // 促销费用变化
      lotChange (val) {
        this.feiyongList.forEach((item, index) => {
          if (item.id === val) {
            if (item.promotionType === 1) {
              this.LotForm.show = false
              this.LotForm.sum = ''
            } else {
              this.LotForm.show = true
            }
          }
        })
      },  // 批量设置促销费用变化
      timeChange (val) {
        this.ruleForm.start_time = val[0]
        this.ruleForm.end_time = val[1]
        activity.cxfy.allList({branchId: this.branchId, activityType: 1, startTime: this.ruleForm.start_time, endTime: this.ruleForm.end_time}, (res) => {
          console.log(res, '费用列表')
          if (res.message === 'ok') {
            this.feiyongList = res.content
            this.r = this.feiyongList.filter(function (x) {
              return x.id
            })
          }
        }) // 获取促销费用
      }, // 时间变化
      add_stair () {
        this.ruleForm.stair.push({
          condition: '',
          reduction: ''
        })
      },     // 创建阶梯
      remove (index) {
        this.ruleForm.stair.splice(index, 1)
      },   // 删除阶梯
      simpleCheck () {
        if (this.ruleForm.time.length === 0) {
          this.$message({
            showClose: true,
            message: '请先选择时间',
            type: 'error'
          })
          return false
        }
        this.formSimple.ID = ''
        this.formSimple.name = ''
        this.formSimple.type1 = ''
        this.formSimple.type2 = ''
        this.formSimple.type3 = ''
        this.formSimple.brand = ''
        this.tableData2 = []
        this.total = ''
        this.dialogSimple = true
      },   // 添加商品弹窗
      lotSet () {
        if (this.tableData.length !== 0) {
          this.dialogLotSet = true
          this.LotForm.feiyong = ''
          this.LotForm.sum = ''
          this.LotForm.show = true
        } else {
          this.$message({
            showClose: true,
            message: '请先选择商品',
            type: 'error'
          })
        }
      },        // 批量设置弹窗
      checkType2 (val) {
        this.productList2 = []
        this.formSimple.type2 = ''
        this.formSimple.brand = ''
        getInfo.getCate({pid: val}, (res) => {
          if (res.message === 'ok') {
            this.productList2 = res.content
          }
        })
      }, // 二级分类
      checkType3 (val) {
        this.productList3 = []
        this.formSimple.type3 = ''
        getInfo.getCate({pid: val}, (res) => {
          if (res.message === 'ok') {
            this.productList3 = res.content
          }
        })
        getInfo.getBrand({cateId: val}, (res) => {
          if (res.message === 'ok') {
            this.brandList = res.content
          }
        })
      }, // 三级分类
      handleChange (all) {
        this.all = all
      }, // 多选
      handleSelectionChange (all) {
        this.all = all
      }, // 多选
      isCheck (row, index) {
        return !row.isActivity && row.name2 === 'add'
      }, // 选择框置灰
      makeLot (val) {
        if (val) {
          var str = val.indexOf('.')
          var numlength = 0
          if (str !== -1) {
            const index = val.substring(str + 1, val.length)
            numlength = index.length
          }
          if (isNaN(val) || (val < 0) || (numlength > 2)) {
            this.$message({
              showClose: true,
              message: '供货商承担金额大于0, 最多为两位小数',
              type: 'error'
            })
            this.LotForm.sum = ''
            return false
          }
        }
        console.log(this.LotForm.feiyong, 'ww')
        this.tableData.forEach((item, index) => {
          item.promotionfeetype = this.LotForm.feiyong
          this.fyChange(this.LotForm.feiyong, item, index)
          item.providerholdprice = this.LotForm.sum
          Vue.set(this.tableData, index, this.tableData[index])
        })
        this.dialogLotSet = false
      }, // 批量设置促销费用和供货商费用
      omit (index, row) {
        this.tableData.splice(index, 1)
      },  // 删除
      top (index, row) {
        this.tableData.splice(0, 0, row)
        this.tableData.splice(index + 1, 1)
      },   // 置顶
      moveT (index, row) {
        this.tableData.splice(index - 1, 0, row)
        this.tableData.splice(index + 1, 1)
      }, // 上移
      moveB (index, row) {
        this.tableData.splice(index + 2, 0, row)
        this.tableData.splice(index, 1)
      }, // 下移 ---------------------------
      add (index, row, event) {
        if (event.target.innerText === '添加') {
          row.name2 = 'cancel'
          this.$refs.multipleTable.toggleRowSelection(row, true)
          const arr = {
            promotionfeetype: '',   // 费用Id
            providerholdprice: '',  // 供货商承担金额
            isSupplier: true,
            productid: row.hmpId,   // 商品ID
            name: row.hmpName,      // 商品名称
            saleunit: row.saleunit, // 销售单位
            salenorm: row.salenorm, // 销售规格
            saleprice: row.price,   // 系统售价
            saleunit_convert: row.saleUnitConvert, // 销售单位和最小单位转换值
            cgunit_convert: row.CGUnitConvert,     // 采购单位和最小单位转换值
            cgprice: row.proBuyPrice,              // 最近一次采购价
            promotionproduct_id: ''                // 新添加商品
          }
          this.tableData.push(arr)
        } else {
          row.name2 = 'add'
          this.$refs.multipleTable.toggleRowSelection(row, false)
          const leng = this.tableData.length
          for (var i = 0; i < leng; i++) {
            var element = this.tableData[i]
            if (Number(element.productid) === Number(row.hmpId)) {
              this.tableData.splice(i, 1)
            }
          }
        }
      },  // 单条添加
      celadd (index, row) {
        row.name2 = 'add'
        this.$refs.multipleTable.toggleRowSelection(row, false)
        const leng = this.tableData.length
        for (var i = 0; i < leng; i++) {
          var element = this.tableData[i]
          if (Number(element.productid) === Number(row.hmpId)) {
            this.tableData.splice(i, 1)
          }
        }
      },
      lotAdd () {
//      状态变为撤销
        this.tableData2.forEach((item1, index1) => {
          this.all.forEach(function (item, index) {
            if (item1.hmpId === item.hmpId) {
              item1.name2 = 'cancel'
            }
          })
        })
//      添加进去
        this.all.forEach((item, index) => {
          if (this.tableData.indexOf(item) === -1) {
            const arr = {
              promotionfeetype: '',   // 费用Id
              providerholdprice: '',  // 供货商承担金额
              isSupplier: true,
              productid: item.hmpId,   // 商品ID
              name: item.hmpName,      // 商品名称
              saleunit: item.saleunit, // 销售单位
              salenorm: item.salenorm, // 销售规格
              saleprice: item.price,   // 系统售价
              saleunit_convert: item.saleUnitConvert, // 销售单位和最小单位转换值
              cgunit_convert: item.CGUnitConvert,     // 采购单位和最小单位转换值
              cgprice: item.proBuyPrice,              // 最近一次采购价
              promotionproduct_id: ''                // 新添加商品
            }
            this.tableData.unshift(arr)
          }
        })
      },                // 批量添加
      simpleList () {
        this.isLoading = true
        const queryData = {
          branchId: this.branchId,
          userType: this.ruleForm.limit_user_type,
          promotionType: 4, // 活动类型
          flag: 1,
          isMaster: 1,
          fourCate: this.formSimple.brand,
          page: this.page,
          pageSize: this.pageSize,
          hmpId: this.formSimple.ID,
          hmpName: this.formSimple.name,
          firstCate: this.formSimple.type1,
          secondCate: this.formSimple.type2,
          thirdCate: this.formSimple.type3,
          startTime: this.ruleForm.start_time,
          endTime: this.ruleForm.end_time,
          classId: this.ruleForm.limit_product_type === '40' ? [40, 41] : [this.ruleForm.limit_product_type],
          showType: [1, 3, 4]
        }
        getInfo.searchProduct(queryData, (res) => {
          console.log(res, '商品分页数据')
          if (res.message === 'ok' && res.content.content !== null) {
            res.content.content.forEach((item, index) => {
              item.isActivity = item.isActivity === null ? '' : item.isActivity.join(',')
              item.price === null ? item.price = '' : item.price = item.price.toFixed(2)
              item.proBuyPrice = item.proBuyPrice.toFixed(2)
            })
            this.isLoading = false
            if (this.tableData.length !== 0) {
              for (var i = 0; i < res.content.content.length; i++) {
                let a = true
                for (var j = 0; j < this.tableData.length; j++) {
                  if (res.content.content[i].hmpId === this.tableData[j].productid) {
                    res.content.content[i].name2 = 'cancel'
                    a = false
                  } else {
                    res.content.content[i].name2 = 'add'
                  }
                  if (a === false) {
                    j = this.tableData.length
                  }
                }
              }
            } else {
              res.content.content.forEach(function (item, index) {
                item.name2 = 'add'
              })
            }
            this.tableData2 = res.content.content
            this.total = res.content.count
          } else if (res.message === 'ok' && res.content.content === null) {
            this.tableData2 = []
            this.total = ''
            this.isLoading = false
          } else {
            this.tableData2 = []
            this.isLoading = false
            this.$message({
              showClose: true,
              message: res.message,
              type: 'error'
            })
            this.total = ''
          }
        })
      },            // 商品分页查询
      handleCurrentChange (val) {
        this.page = val
        this.simpleList()
      }, // 分页
      editIn (id) {
        activity.sphd.detail({id: id}, (res) => {
          console.log(res, '满减详情')
          if (res.message === 'ok') {
            res.content.limit_full_reduction = JSON.parse(res.content.limit_full_reduction)
            res.content.limit_full_reduction.forEach((item, index) => {
              item.reduction = Number(item.reduction / 100).toFixed(2)
              item.condition = Number(item.condition / 100).toFixed(2)
            })
            this.detailData = res.content
            if (this.detailData.limit_usertypetag_id && this.detailData.limit_usertypetag_id !== '0') {
              this.arr = this.detailData.limit_usertypetag_id.split(',').map(value => {
                return parseInt(value)
              })
            } else {
              this.arr = []
            }
            // 数据赋值
            this.timeChange([res.content.start_time, res.content.end_time])
            this.ruleForm.time = [res.content.start_time, res.content.end_time]
            this.ruleForm.start_time = res.content.start_time
            this.ruleForm.end_time = res.content.end_time
            this.ruleForm.limit_store_id = Number(res.content.limit_store_id)
            this.ruleForm.name = res.content.promotion_name
//            if (res.content.sales_cost) {
//              this.contain = '2'
//              this.ruleForm.sales_cost = Number(res.content.sales_cost)
//              this.ruleForm.sales_ratio = res.content.sales_ratio
//              const self = this
//              setTimeout(function () {
//                self.fyChange2(Number(res.content.sales_cost))
//              }, 500)
//            }
            res.content.ad_words ? this.ruleForm.ad_words = res.content.ad_words : this.ruleForm.ad_words === ''
            res.content.sub_ad_words ? this.ruleForm.sub_ad_words = res.content.sub_ad_words : this.ruleForm.sub_ad_words === ''
            this.ruleForm.ad_pic = res.content.ad_pic
            this.ruleForm.title = res.content.sub_promotion_name
            this.ruleForm.limit_usertypetag_id = this.arr
            this.ruleForm.limit_type = String(res.content.limit_type)
            this.ruleForm.limit_product_type = String(res.content.product_type)
            if (res.content.limit_type === '1') {
              this.ruleForm.stair = res.content.limit_full_reduction
            } else {
              this.ruleForm.limit_full_reduction[0].condition = res.content.limit_full_reduction[0].condition
              this.ruleForm.limit_full_reduction[0].reduction = res.content.limit_full_reduction[0].reduction
            }
            this.ruleForm.remark = res.content.remark
            res.content.main_product.forEach((item, index) => {
              item.cgprice = Number(item.cgprice / 100).toFixed(2)
              item.saleprice = Number(item.saleprice / 100).toFixed(2)
              const self = this
              setTimeout(function () {
                self.fyChange(item.promotionfeetype, item, index)
              }, 500)
              if (item.providerholdprice === 0) {
                item.providerholdprice = ''
              } else {
                item.providerholdprice = Number(item.providerholdprice / 100).toFixed(2)
              }
            })
            this.testOver(res.content.main_product)
            this.tableData = res.content.main_product
          } else {
            this.$message({
              showClose: true,
              message: res.message,
              type: 'error'
            })
          }
        })
      },     // 编辑回写
      submit (event, formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            const start = new Date(this.ruleForm.start_time).getTime()
            const now = new Date().getTime()
            if (this.ruleForm.name === '') {
              this.$message({
                showClose: true,
                message: '请输入活动名称',
                type: 'error'
              })
              return false
            }
//            if (this.ruleForm.sales_cost === '' && this.contain === '2') {
//              this.$message({
//                showClose: true,
//                message: '请选择所属费用',
//                type: 'error'
//              })
//              return false
//            }
            if (start < now) {
              this.$message({
                showClose: true,
                message: '活动开始时间要晚于当前时间',
                type: 'error'
              })
              return false
            }
            if (this.ruleForm.limit_type === '1') {
              for (var m = 0; m < this.ruleForm.stair.length - 1; m++) {
                if (Number(this.ruleForm.stair[m + 1].condition) <= Number(this.ruleForm.stair[m].condition) || Number(this.ruleForm.stair[m + 1].reduction) < Number(this.ruleForm.stair[m].reduction)) {
                  this.$message({
                    showClose: true,
                    message: '每个阶梯必须大于上个阶梯',
                    type: 'error'
                  })
                  return false
                }
              }
              for (var n = 0; n < this.ruleForm.stair.length; n++) {
                if (this.ruleForm.stair[n].reduction === '' || this.ruleForm.stair[n].condition === '') {
                  this.$message({
                    showClose: true,
                    message: '请输入完整的阶梯内容！',
                    type: 'error'
                  })
                  return false
                }
                if (Number(this.ruleForm.stair[n].reduction) > Number(this.ruleForm.stair[n].condition)) {
                  this.$message({
                    showClose: true,
                    message: '阶梯规格不合理！',
                    type: 'error'
                  })
                  return false
                }
              }
            } else {
              if (this.ruleForm.limit_full_reduction[0].reduction === '' || this.ruleForm.limit_full_reduction[0].condition === '') {
                this.$message({
                  showClose: true,
                  message: '请输入每满内容！',
                  type: 'error'
                })
                return false
              }
              if (Number(this.ruleForm.limit_full_reduction[0].reduction) > Number(this.ruleForm.limit_full_reduction[0].condition)) {
                this.$message({
                  showClose: true,
                  message: '每满规格不合理！',
                  type: 'error'
                })
                return false
              }
            }
            var newData1 = []
            if (this.ruleForm.limit_type === '1') {
              newData1 = JSON.parse(JSON.stringify(this.ruleForm.stair))
              newData1.forEach((item, index) => {
                item.reduction = (Number(item.reduction).toFixed(2) * 100).toFixed(0)
                item.condition = (Number(item.condition).toFixed(2) * 100).toFixed(0)
              })
            } else {
              newData1 = JSON.parse(JSON.stringify(this.ruleForm.limit_full_reduction))
              newData1.forEach((item, index) => {
                item.reduction = (Number(item.reduction).toFixed(2) * 100).toFixed(0)
                item.condition = (Number(item.condition).toFixed(2) * 100).toFixed(0)
              })
            }
            if (this.tableData.length === 0) {
              this.$message({
                showClose: true,
                message: '商品信息至少为一条',
                type: 'error'
              })
              return false
            }
            const newData = JSON.parse(JSON.stringify(this.tableData))
            if (this.contain === '2') {
              newData.forEach((item, index) => {
                item.cgprice = (item.cgprice * 100).toFixed(0)
                item.saleprice = (item.saleprice * 100).toFixed(0)
                item.providerholdprice = 0.00
                item.promotionfeetype = 297
              })
            } else {
              newData.forEach((item, index) => {
                item.cgprice = (item.cgprice * 100).toFixed(0)
                item.saleprice = (item.saleprice * 100).toFixed(0)
                item.providerholdprice = (item.providerholdprice * 100).toFixed(0)
              })
            }
            const Data = {
              sales_cost: this.ruleForm.sales_cost,
              sales_ratio: Number(this.ruleForm.sales_ratio),
              end_time: this.ruleForm.end_time,
              ad_words: this.ruleForm.ad_words,
              sub_ad_words: this.ruleForm.sub_ad_words,
              ad_pic: this.ruleForm.ad_pic,
              start_time: this.ruleForm.start_time,
              gwId: this.roleId,
              iscaogao: event.target.innerText === '提交' ? 2 : 1,
              limit_attend_count: this.ruleForm.num,
              limit_product_type: this.ruleForm.limit_product_type,
              limit_usertypetag_id: this.ruleForm.limit_usertypetag_id.join(','), // 客户标签
              limit_branch_id: this.branchId,
              limit_department: this.orgId,
//          limit_full_reduction: this.ruleForm.limit_type === '1' ? this.ruleForm.stair : this.ruleForm.limit_full_reduction,
              limit_full_reduction: newData1,
              limit_store_id: this.ruleForm.limit_store_id,
              limit_type: this.ruleForm.limit_type,
              limit_user_type: this.ruleForm.limit_user_type,
              newBranchId: this.bid,
              product: newData,
              promotion_name: this.ruleForm.name,
              remark: this.ruleForm.remark,
              sub_title: this.ruleForm.title,
              uorId: this.uorId,
              userId: this.userId,
              userName: this.userName
            }
            console.log(Data, '提交数据')
            if (!this.data || this.$store.state.tab.menuId === 'manjian_fz') {
              activity.sphd.myj.manjian.create(Data, (res) => {
                if (res.code === 0) {
                  if (this.$store.state.tab.menuId === 'manjian_fz') {
                    this.$store.dispatch('delTab', {id: 'manjian_fz'})
                  } else {
                    this.$store.dispatch('delTab', {id: 'manjian_add'})
                  }
                  this.$store.dispatch('xinmanjianState', this.$store.state.updateState.xinmanjianState + 1)
                  this.$message({
                    showClose: true,
                    message: res.message,
                    type: 'success'
                  })
                } else if (res.code === 6060) {
                  this.tableData = []
                  this.$message({
                    showClose: true,
                    message: res.message,
                    type: 'error'
                  })
                } else if (res.code === 5050) {
                  console.log(res, '异常')
                  this.changeGoodsList = []     // 调价后的数组
                  this.checkOutChangeGoods(res) // 检验调价后的商品
                  this.changeGoodFlag = true    // 调价商品显示
                  this.$message({
                    showClose: true,
                    message: res.message,
                    type: 'error'
                  })
                } else {
                  this.$message({
                    showClose: true,
                    message: res.message,
                    type: 'error'
                  })
                }
              })
            } else {
              Data.id = this.data.id
              Data.promotion_id = this.data.promotion_id
              activity.sphd.myj.manjian.edit(Data, (res) => {
                if (res.code === 0) {
                  this.$store.dispatch('delTab', {id: 'manjian_bj'})
                  this.$store.dispatch('xinmanjianState', this.$store.state.updateState.xinmanjianState + 1)
                  this.$message({
                    showClose: true,
                    message: res.message,
                    type: 'success'
                  })
                } else if (res.code === 5050) {
                  this.changeGoodsList = []     // 调价后的数组
                  this.checkOutChangeGoods(res) // 检验调价后的商品
                  this.changeGoodFlag = true    // 调价商品显示
                  this.$message({
                    showClose: true,
                    message: res.message,
                    type: 'error'
                  })
                } else {
                  this.$message({
                    showClose: true,
                    message: res.message,
                    type: 'error'
                  })
                }
              })
            }
          } else {
            return false
          }
        })
      },  // 提交 / 暂存
      cancel () {
        if (!this.data) {
          this.$store.dispatch('delTab', {id: 'manjian_add'})
        } else {
          this.$store.dispatch('delTab', {id: this.datas.menuId})
        }
      },       // 取消
      beforeUpload (file) {
        if (this.ruleForm.time.length === 0) {
          this.$message({
            showClose: true,
            message: '请先选择时间',
            type: 'error'
          })
          return false
        }
        this.$store.dispatch('pageLoading', true)
        let fd = new window.FormData()
        fd.append('file', file)
        fd.append('branchId', this.branchId)
        fd.append('promotionType', 4)
        fd.append('startTime', this.ruleForm.start_time)
        fd.append('endTime', this.ruleForm.end_time)
        fd.append('isMaster', 1)
        axios({
          method: 'post',
          url: this.fileUrl,
          data: fd
        }).then(res => {
          console.log(res)
          if (res.data.code === 0) {
            this.tableData = []
            const resData = res.data.content.content
            resData.forEach((item, index) => {
              const arr = {
                promotionfeetype: '',   // 费用Id
                providerholdprice: '',  // 供货商承担金额
                isSupplier: true,
                productid: item.hmpId,   // 商品ID
                name: item.hmpName,      // 商品名称
                saleunit: item.saleunit, // 销售单位
                salenorm: item.salenorm, // 销售规格
                saleprice: item.price.toFixed(2),   // 系统售价
                saleunit_convert: item.saleUnitConvert, // 销售单位和最小单位转换值
                cgunit_convert: item.cGUnitConvert,     // 采购单位和最小单位转换值  大小写
                cgprice: item.proBuyPrice.toFixed(2),              // 最近一次采购价
                promotionproduct_id: ''                 // 新添加商品
              }
              this.tableData.unshift(arr)
              this.$store.dispatch('pageLoading', false)
            })
          } else {
            this.$store.dispatch('pageLoading', false)
            this.$message({
              showClose: true,
              message: res.data.message,
              type: 'error'
            })
          }
        }).catch(res => {
          this.$store.dispatch('pageLoading', false)
          this.$message({
            showClose: true,
            message: res.data.message,
            type: 'error'
          })
        })
        return true
      },  // 导入
      changeGoodsClick () {
//         for (let index = 0; index < this.tableData.length; index++) {
//           const element = this.tableData[index]
//           for (let index2 = 0; index2 < this.changeGoodsList.length; index2++) {
//             const element2 = this.changeGoodsList[index2]
//             if (element.productid === element2.productid) {
//               element.saleunit = element2.saleunit
//               element.salenorm = element2.salenorm
//               element.saleprice = element2.saleprice
// //              element.oldml = element.saleprice === null ? '' : (Number(element.saleprice) - Number(element.cgprice)).toFixed(2)
// //              this.valueToTable('', index, '促销价')
//             }
//           }
//         }
//         this.isRed = false
//         this.isGreen = true
        for (let index = 0; index < this.tableData.length; index++) {
          const element = this.tableData[index]
          for (let index2 = 0; index2 < this.changeGoodsList.length; index2++) {
            const element2 = this.changeGoodsList[index2]
            if (element.productid === element2.productid) {
              if (element2.canNotSale === true || element2.priceChangeIng === true) {
                console.log('删除')
                // for (var k = 0; k < this.goodsSearchList.length; k++) {
                //   var element3 = this.goodsSearchList[k]
                //   if (Number(element3.productid) === Number(element.productid)) {
                //     element3.operation = 0
                //   }
                // }
                this.tableData.splice(index, 1)
                index = index - 1
                // this.computeComb()
              } else {
                element.saleunit = element2.saleunit
                element.salenorm = element2.salenorm
                element.saleprice = element2.saleprice
                // element.oldml = element.saleprice === null ? '' : (Number(element.saleprice) - Number(element.cgprice)).toFixed(2)
                // this.valueToTable('', index, '促销价')
                this.isRed = false
                this.isGreen = true
              }
            }
          }
        }
      },       // 一键修改
      checkOutChangeGoods (res) {
        res.content.forEach((element, index) => {
          this.tableData.forEach((element2, index2) => {
            if (Number(element.hmpId) === Number(element2.productid)) {
              element2.saleunitFlag = element.saleUnitChange
              element2.salenormFlag = element.saleNormChange
              element2.salepriceFlag = element.priceChange
              this.tableIndex.push(index2)
            }
          })
          this.changeGoodsList.push(this.goodsListMap(element, ''))
        })
      },       // 校验调价商品
      goodsListMap (eleRes, isMaster) { // 商品列表映射
        var goodsObj = {
          'stateName': eleRes.changeDes,
          'productid': eleRes.hmpId, // 商品id
          'name': eleRes.hmpName, // 商品名称
          'saleunit': eleRes.saleunit, // 销售单位
          'salenorm': eleRes.salenorm, // 销售规格
          'saleprice': eleRes.price === null ? '' : Number(eleRes.price).toFixed(2), // 系统售价
          'saleunitFlag': false,
          'salenormFlag': false,
          'salepriceFlag': false,
          'canNotSale': eleRes.canNotSale ? eleRes.canNotSale : '', // 商品不能卖 true 不能卖
          'priceChangeIng': eleRes.priceChangeIng ? eleRes.priceChangeIng : '', // 商品不能卖 true 不能卖
          // 'oldml': eleRes.hmpBuyPrice - eleRes.proBuyPrice, // 原毛利 // 商品原毛利=商品系统售价-商品上次入库成本价
          'cxml': '', // 促销毛利
          'cxmls': '', // 毛利损失
          'countState': false, // 计算状态
          'is_master': isMaster, // 是否为主商品
          'promotionproduct_id': '' // 商品主键ID
        }
        return goodsObj
      }, // 商品字段映射
      tableRowClassName (row, index) {
        for (let index2 = 0; index2 < this.tableIndex.length; index2++) {
          console.log(this.tableIndex)
          const element = this.tableIndex[index2]
          if (index === element) {
            console.log(index2, element)
            console.log('aaaaa')
            return 'highlight'
          }
        }
      }   // 给table加某一行的样式
    },
    computed: mapState({
      userName: function (state) {
        return state.user.info.user_name
      },
      userId: function (state) {
        return state.user.info.user_id
      },
      orgName: function (state) {
        return state.user.info.parOrgName
      },
      orgId: function (state) {
        return state.user.info.or_org_id
      },
      roleId: function (state) {
        return Number(state.user.info.roleid)
      },
      uorId: function (state) {
        return Number(state.user.info.uor_id)
      },
      branchName: function (state) {
        return state.user.info.branchId === 1 ? '总公司' : state.user.info.branchName
      },
      branchId: function (state) {
        return state.user.info.branchId
      },
      bid: function (state) {
        return state.user.info.branchOrgId
      },
      user_telphone: function () {
        return this.$store.state.user.info.user_telphone
      }
    }),
    created () {
      this.imgHost = apiHost.imgHost
      this.imgAddress = 'http://' + apiHost.newCms + ':20000' + apiURL.upLoadImage
      this.fileUrl = 'http://' + apiHost.newCms + ':20000' + apiURL.manjian_upload // 导入表格
      getInfo.getCate({pid: 0}, (res) => {
        if (res.message === 'ok') {
          this.productList1 = res.content
        }
      }) // 商品一级分类
      getInfo.getLabel({userType: 1}, (res) => {
        if (res.message === 'ok') {
          res.content.forEach((item, index) => {
//            item.disabled = true
            if (item.labelCode !== 6) {
              item.disabled = true
            }
          })
          this.labelList = res.content
        }
      }) // 客户标签
      this.data = this.$store.state.tab.uid     //  row
      this.datas = this.$store.state.tab
      if (this.data) {
        this.editIn(this.data.id)
      } // 数据回显
    }
  }
</script>
<style>
  .dialog .el-form--inline div {
    display: inline-block;
    float: left;
  }
  .stair {
    margin-left: 66px;
    font-size: 14px;
    color: #48576a;
  }
  .daoru .el-upload-list {
    display: none;
  }
  .el-table .red {
    color: red
  }
  .el-table .green {
    color: rgb(72, 185, 72)
  }
</style>
